package com.itheima.homework.hw01.part02;

import java.util.*;

public class DualColoredBall {
    Random r = new Random();

    public void start() {
        Set<Integer> redBalls = new HashSet<>();//整理前的集合
        List<Integer> sortRedBalls = new ArrayList<>();//遍历整理后接收的集合
        prepareTheRedBall(redBalls);//传入整理前的集合，填入随机6颗红球
        for (Integer r : redBalls) sortRedBalls.add(r);//循环遍历整理前的集合，一次add到整理后的集合
        Collections.sort(sortRedBalls, (o1, o2) -> Integer.compare(o1, o2));//为整理后的集合排序
        System.out.println(sortRedBalls + "[" + (r.nextInt(16) + 1) + "]");//print
    }

    private void prepareTheRedBall(Set<Integer> redBalls) {
        while (redBalls.size() < 6) redBalls.add(r.nextInt(33) + 1);
    }
}
